import threading

a = 0

#创建互拆锁，Lock本质上是一个函数，通过调用函数，创建互拆锁
lock = threading.Lock()

def add1():
    #上锁
    lock.acquire()
    for i in range(10000):
        global a
        a+=1
    print(f'add1--{a}')
    lock.release()


def add2():
    lock.acquire()
    for i in range(10000):
        global a
        a+=1
    print(f'add2--{a}')
    lock.release()

if __name__ == '__main__':
    thread1=threading.Thread(target=add1)
    thread2=threading.Thread(target=add2)
    thread1.start()
    thread2.start()
    print(a)